﻿@using OA.Model;
@model OA.Model.Voucher
@{
    Layout = "~/Areas/Member/Views/Shared/_Layer_Layout.cshtml";
    Approval infoApproval = ViewBag.InfoApproval;
}
<div class="layui-form layui-tab-content" id="LAY_ucm" style="padding:0px">
    @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
    {
        @Html.AntiForgeryToken()
        <input type="hidden" value="@infoApproval.CustomID" name="customFormID" />
        <input type="hidden" value="@infoApproval.FormID" name="formID" />
        <div class="layui-form-item">
            <label class="layui-form-label" for="Countersign">抄送人</label>
            <div class="layui-input-block">
                <input type="text" placeholder="请输入抄送人员" class="layui-input autocomplete" value="">
                <table class="layui-table countersignTable">
                    <thead>
                        <tr><th>抄送部门</th><th>抄送岗位</th><th>抄送人</th><th style="width:32px;">#</th></tr>
                    </thead>
                    <tbody>
                        @*@for (int i = 0; i < Model.CountersignEmployees.Count; i++)
                        {
                            CountersignEmployee item = Model.CountersignEmployees[i];
                            <tr data-id="@i" class="Countersign_@item.EmpID"><td>@item.DepatrmentName</td><td><input type="hidden" class="Status" value="@item.Status" name="CountersignEmployees[@i].Status" /><input type="hidden" value="@item.PositionID" name="CountersignEmployees[@i].PositionID" /> @item.PositionName</td><td>@item.EmpName <input type="hidden" value="@item.EmpID" name="CountersignEmployees[@i].EmpID" /></td><td><span class="delete">删除</span></td></tr>
                        }*@
                    </tbody>
                </table>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" value="提 交" class="layui-btn mySubmit" />
            </div>
        </div>
    }
</div>
<script type="text/javascript" src="/Member/Home/GetDepartmentAndPosition"></script>
<script type="text/javascript" src="~/js/department.js"></script>
<script type="text/javascript">
    layui.use(['form','autocomplete', 'element', 'layer'], function () {
		form = layui.form;
        layer = layui.layer;
        element = layui.element;
        autocomplete = layui.autocomplete;
        autocomplete.render({
            elem: $('.autocomplete'),
            url: '/Member/Home/GetEmployees',
            cache: false,
            template_val: '{p:"{d.p}}",s:"{d.s}}",i:"{d.i}}",n:"{d.n}}",d:"{d.d}}",}',
            template_txt: '{{d.n}} <span class=\'layui-badge layui-bg-gray\'>{{d.d}}&nbsp;{{d.s}}&nbsp;{{d.n}}</span>',
            onselect: function (resp) {
                $('.autocomplete').val("");
                if (resp.i == "@Model.Sponsor") {
                    layer.msg("不能抄送给自己");
                    return;
                }
                var trLength = $(".countersignTable tbody").find("tr").length;
                var indexStep = parseInt(trLength) + 1;
                if ($(".Countersign_" + resp.i).length > 0) return;
                $(".countersignTable tbody").append('<tr  data-id="' + trLength + '" class="Countersign_' + resp.i + '"><td><input type="hidden" value="1" name="CountersignEmployees[' + trLength + '].Status"/><input type="hidden" value="' + resp.p + '" name="CountersignEmployees[' + trLength + '].PositionID"/>' + resp.d + '</td><td><input type="hidden" value="' + resp.i + '" name="CountersignEmployees[' + trLength + '].EmpID"/>' + resp.s + '</td><td>' + resp.n
                    + '</td><td><span class="delete">删除</span></td></tr>');
            }
        })
    });
    $(document).on("click", ".deleteItem", function () {
        $(this).parent().parent().css("display", "none");
        $(this).parent().parent().find(".Status").val("-1");
    });

    $(".mySubmit").click(function () {
        $.ajax({
            url: $("#myForm").prop("action"),
            type: "Post",
            data: $("#myForm").serialize(),
            dataType: "json",
            beforeSend: function () {
                layer.msg("正在提交，请稍后...");
                $(".mySubmit").prop('disabled', true);
            },
            success: function (data) {
                if (data.State == 400) {
                    $(".mySubmit").prop('disabled', false);
                    layer.msg(data.Msg);
                    return;
                }
                if (data.State == 402) {
                    $(".mySubmit").prop('disabled', false);
                    layer.msg(data.Msg);
                    return;
                }
                else {
                    window.parent.CarbonCopyCallBack();
                }
            }
        });

    });

</script>
